import { Radio, Typography } from "antd";
import React from "react";
import { QuestionRadioDefaultProps, QuestionRadioPropsType } from "./interface";
import useQuestionPageType from "../../../../hooks/useQuestionPageType";
import commonStyles from "../common.module.scss";
import { genFontSize } from "../../../../utils/common";

const Component: React.FC<QuestionRadioPropsType> = (
  props: QuestionRadioPropsType
) => {
  const {
    title,
    options = [],
    value,
    prompt,
    isVertical,
  } = {
    ...QuestionRadioDefaultProps,
    ...props,
  };
  // 判断当前页面，如果是统计页则选中提示答案项，如果是编辑页则显示选中默认项
  const { isStatPage } = useQuestionPageType();

  return (
    <div>
      <Typography.Title
        level={5}
        style={{
          fontSize: genFontSize(5),
        }}
        className={commonStyles.h5}
      >
        {title}
      </Typography.Title>
      <Radio.Group
        options={options}
        value={isStatPage ? prompt : value}
        className={isVertical ? commonStyles.vertical : ""}
      />
    </div>
  );
};

export default Component;
